﻿//-----------------------------------------------------------------------
// <copyright file="LockBase.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Threading;

#endregion

/*
 * SOURCES:
 * http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx
 */

namespace GateShift.Services.SDK.Threading.Locking
{
    /// <summary>
    /// Locking class base for all locking type objects
    /// </summary>
    public abstract class LockBase : IDisposable
    {
        /// <summary>
        /// Initializes a new instance of the LockBase class
        /// </summary>
        /// <param name="lockObject">ReaderWriterLockSlim containing the locking states</param>
        protected LockBase(ReaderWriterLockSlim lockObject)
        {
            if (lockObject == null)
            {
                throw new ArgumentNullException("lockObject");
            }

            LockObject = lockObject;
        }

        /// <summary>
        /// Gets the reference to the locking object
        /// </summary>
        protected ReaderWriterLockSlim LockObject { get; private set; }

        /// <summary>
        /// Disposes the lock
        /// </summary>
        public abstract void Dispose();
    }
}